// Angular Version 6 below need to be deleted {providedIn: 'root'}

// angular
import {Injectable} from '@angular/core';
import {HttpParams} from '@angular/common/http';
// owner
import {Request} from 'pengesoft-ng-lib';
// models
import {HouseList} from '../domains/houselist.domain';

/**
 * 
 */
@Injectable({
  providedIn: 'root'
})
export class CollectServiceSvr {
  private readonly baseUrl: string;

  constructor(
    private request: Request
  ) {
    this.baseUrl = 'CollectServiceSvr.assx/';
  }

  
  saveCollection(token: string, customerId: string, houseId: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('houseId', houseId.toString());
    return this.request.post<number>(this.baseUrl + 'saveCollection', httpParams).then((res) => {
      return res;
    });
  }

  
  deleteCollection(token: string, collectionIds: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('collectionIds', collectionIds.toString());
    return this.request.post<number>(this.baseUrl + 'deleteCollection', httpParams).then((res) => {
      return res;
    });
  }

  
  GetVersion(): Promise<string> {
    const httpParams = new HttpParams();
    return this.request.post<string>(this.baseUrl + 'GetVersion', httpParams).then((res) => {
      return res;
    });
  }

  
  listCollection(token: string, customerId: string): Promise<HouseList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString());
    return this.request.post<HouseList>(this.baseUrl + 'listCollection', httpParams).then((res) => {
      return new HouseList(res);
    });
  }
}
